package com.jee.mql.dao;

import java.util.ArrayList;
import java.util.List;

import com.jee.mql.model.User;

public class UserDaoJdbc implements IDao {


	public void ajouterUser(User u) {
		DataSource ds = new MySqlDataSource("zakariadb");
		Database db = new Database(ds);
		db.insert(u);
		db.close();
		
	}


	public User rechercherUser(String login) {
		DataSource ds = new MySqlDataSource("zakariadb");
		Database db = new Database(ds);
		String str[] = db.select("user","login", login);
		User u = new User(str[0], str[1]);
		return u;
	}


	public void modifierUser(User u, int pos) {
		DataSource ds = new MySqlDataSource("zakariadb");
		Database db = new Database(ds);
		
		db.update(u);
	}

	
	public List<User> afficherUsers() {
		DataSource ds = new MySqlDataSource("zakariadb");
		Database db = new Database(ds);
		List<User> users = new ArrayList<User>();
		
		String str[][] = db.select("user");
		
		for (int i = 0; i < str.length -1; i++) {
			users.add(new User(str[i][0], str[i][1]));
		}
		return users;
	}

	
	public void supprimerUser(String login) {
		
	}

}
